import { getAttrAreas, getAttrType } from '@/api/travel'

const state = {
  attrId: 2,
  attraction: {},
  areas: [],
  attrTypes: [],
  showAttrDetail: false
}

const mutations = {
  SET_ATTR_ID: (state, attrId) => {
    state.attrId = attrId
  },
  SET_ATTRACTION: (state, attraction) => {
    state.attraction = attraction
  },
  SET_AREAS: (state, areas) => {
    state.areas = areas
  },
  SET_ATTR_TYPES: (state, attrTypes) => {
    state.attrTypes = attrTypes
  },
  SET_SHOW_ATTR_DETAIL: (state, showAttrDetail) => {
    state.showAttrDetail = showAttrDetail
  }
}

const actions = {
  // 获取地区
  async getAreas({ commit }) {
    const res = await getAttrAreas()
    if (res.code === 200) {
      const { areas } = res.data
      commit('SET_AREAS', areas)
    } else {
      console.log(res.message)
    }
  },

  // 获取景区类别
  async getAttrTypes({ commit }) {
    const res = await getAttrType()
    if (res.code === 200) {
      const { attrTypes } = res.data
      commit('SET_ATTR_TYPES', attrTypes)
    } else {
      console.log(res.message)
    }
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
